package cn.change360.newappchildrenenglish.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.change360.newappchildrenenglish.R;

/**
 * Created by Jacky on 2015/11/12.
 */

public class WidgetWord extends LinearLayout {

    ImageView word_img,word_this;

    public WidgetWord(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public WidgetWord(Context context) {
        super(context);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.widget_word, this);
        word_img = (ImageView) findViewById(R.id.word_img);
        word_this = (ImageView) findViewById(R.id.word_this);
        word_this.setVisibility(GONE);
    }

    private void init(Context context, AttributeSet attrs) {
        initView(context);
        final TypedArray typedArray = getContext().obtainStyledAttributes(
                attrs, R.styleable.WidgetWord);
        Drawable icons = null;
        if (typedArray.hasValue(R.styleable.WidgetWord_word_img)) {
            icons = typedArray.getDrawable(R.styleable.WidgetWord_word_img);
            icons.setCallback(this);
        }
        if (icons != null) {
            word_img.setImageDrawable(icons);
        }
        typedArray.recycle();
    }

    public void setImg(Drawable drawable) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            word_img.setBackground(drawable);
        } else {
            word_img.setImageDrawable(drawable);
        }
    }

    public void setThis(){
        word_this.setVisibility(VISIBLE);
    }
}